package com.ding.demo.recursive;

import java.util.concurrent.RecursiveAction;

public class RaskDemo extends RecursiveAction {


    private static final int MAX = 20;

    private int start;
    private int end;

    public RaskDemo(int start, int end) {
        this.start = start;
        this.end = end;
    }

    @Override
    protected void compute() {
        //当end-start的值小于MAX时，开始打印
        if((end-start) < MAX) {
            for(int i= start; i<end;i++) {
                System.out.println("开始干活。。。。。");
                System.out.println(Thread.currentThread().getName()+"i的值"+i);
            }
        }else {
            System.out.println("分配任务。。。。。。。");
            // 将大任务分解成两个小任务
            int middle = (start + end) / 2;
            RaskDemo left = new RaskDemo(start, middle);
            RaskDemo right = new RaskDemo(middle, end);
            left.fork();
            right.fork();

        }
    }

}
